
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>从Chrome V8源码看JavaScript数组 · 👨🏽‍💻前端漫游指南</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="WuXiaolong">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="LRU算法.html" />
    
    
    <link rel="prev" href="统计算法的执行效率和资源消耗.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                        <b>1.1.</b>
                    
                    介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../Base/">
            
                <a href="../Base/">
            
                    
                        <b>1.2.</b>
                    
                    前端基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../Base/">
            
                <a href="../Base/">
            
                    
                        <b>1.2.1.</b>
                    
                    原生js系列
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.1" data-path="../Base/手写call1.html">
            
                <a href="../Base/手写call1.html">
            
                    
                        <b>1.2.1.1.</b>
                    
                    类型转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.2" data-path="../Base/EventLoop.html">
            
                <a href="../Base/EventLoop.html">
            
                    
                        <b>1.2.1.2.</b>
                    
                    EventLoop
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../Base/CSS.html">
            
                <a href="../Base/CSS.html">
            
                    
                        <b>1.2.2.</b>
                    
                    CSS系列
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.2.1" data-path="../Base/布局系列.html">
            
                <a href="../Base/布局系列.html">
            
                    
                        <b>1.2.2.1.</b>
                    
                    布局系列
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../Design/">
            
                <a href="../Design/">
            
                    
                        <b>1.3.</b>
                    
                    前端设计模式
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../Design/工程模式.html">
            
                <a href="../Design/工程模式.html">
            
                    
                        <b>1.3.1.</b>
                    
                    工厂模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../Design/单一模式.html">
            
                <a href="../Design/单一模式.html">
            
                    
                        <b>1.3.2.</b>
                    
                    单一模式
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../DiyCode/">
            
                <a href="../DiyCode/">
            
                    
                        <b>1.4.</b>
                    
                    手撕代码
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../DiyCode/手写call.html">
            
                <a href="../DiyCode/手写call.html">
            
                    
                        <b>1.4.1.</b>
                    
                    手写call
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../DiyCode/手写bind.html">
            
                <a href="../DiyCode/手写bind.html">
            
                    
                        <b>1.4.2.</b>
                    
                    手写bind
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="./">
            
                <a href="./">
            
                    
                        <b>1.5.</b>
                    
                    前端算法
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="前端算法.html">
            
                <a href="前端算法.html">
            
                    
                        <b>1.5.1.</b>
                    
                    前端算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="统计算法的执行效率和资源消耗.html">
            
                <a href="统计算法的执行效率和资源消耗.html">
            
                    
                        <b>1.5.2.</b>
                    
                    统计算法的执行效率和资源消耗
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.3" data-path="从Chrome V8源码看JavaScript数组.html">
            
                <a href="从Chrome V8源码看JavaScript数组.html">
            
                    
                        <b>1.5.3.</b>
                    
                    从Chrome V8源码看JavaScript数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="LRU算法.html">
            
                <a href="LRU算法.html">
            
                    
                        <b>1.5.4.</b>
                    
                    LRU算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="链表原来如此简单.html">
            
                <a href="链表原来如此简单.html">
            
                    
                        <b>1.5.5.</b>
                    
                    链表原来如此简单
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../Vue/">
            
                <a href="../Vue/">
            
                    
                        <b>1.6.</b>
                    
                    Vue知识点
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../Vue/Proxy 基本使用与defineProperty.html">
            
                <a href="../Vue/Proxy 基本使用与defineProperty.html">
            
                    
                        <b>1.6.1.</b>
                    
                    Proxy 基本使用与defineProperty
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../Vue/面试题串讲_vue.html">
            
                <a href="../Vue/面试题串讲_vue.html">
            
                    
                        <b>1.6.2.</b>
                    
                    面试题串讲_vue
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../React/">
            
                <a href="../React/">
            
                    
                        <b>1.7.</b>
                    
                    React知识点
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../React/setState解析.html">
            
                <a href="../React/setState解析.html">
            
                    
                        <b>1.7.1.</b>
                    
                    setState解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../React/Fetch异步中止.html">
            
                <a href="../React/Fetch异步中止.html">
            
                    
                        <b>1.7.2.</b>
                    
                    Fetch异步中止
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../React/面试题串讲_react.html">
            
                <a href="../React/面试题串讲_react.html">
            
                    
                        <b>1.7.3.</b>
                    
                    面试题串讲_react
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../ReactNative/">
            
                <a href="../ReactNative/">
            
                    
                        <b>1.8.</b>
                    
                    ReactNative
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../ReactNative/RN分包机制.html">
            
                <a href="../ReactNative/RN分包机制.html">
            
                    
                        <b>1.8.1.</b>
                    
                    RN分包机制
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >从Chrome V8源码看JavaScript数组</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x4ECE;chrome-v8&#x6E90;&#x7801;&#x770B;javascript&#x6570;&#x7EC4;">&#x4ECE;Chrome V8&#x6E90;&#x7801;&#x770B;JavaScript&#x6570;&#x7EC4;</h1>
<h3 id="&#x7B80;&#x4ECB;">&#x7B80;&#x4ECB;</h3>
<p>&#x6570;&#x7EC4;&#x3001;&#x94FE;&#x8868;&#x3001;&#x6808;&#x3001;&#x961F;&#x5217;&#x90FD;&#x662F;&#x7EBF;&#x6027;&#x8868;&#xFF0C;&#x5B83;&#x8868;&#x793A;&#x7684;&#x7ED3;&#x6784;&#x90FD;&#x662F;&#x4E00;&#x6BB5;&#x7EBF;&#x6027;&#x7684;&#x7ED3;&#x6784;&#xFF0C;&#x4E0E;&#x4E4B;&#x5BF9;&#x5E94;&#x7684;&#x5C31;&#x662F;&#x975E;&#x7EBF;&#x6027;&#x8868;&#xFF0C;&#x4F8B;&#x5982;&#x6811;&#x3001;&#x56FE;&#x3001;&#x5806;&#x7B49;&#xFF0C;&#x5B83;&#x8868;&#x793A;&#x7684;&#x7ED3;&#x6784;&#x90FD;&#x975E;&#x7EBF;&#x6027;&#x3002;</p>
<p>&#x672C;&#x8282;&#x4E3B;&#x8981;&#x4ECB;&#x7ECD; JavaScript &#x6570;&#x7EC4;&#xFF0C;&#x5728;&#x5F00;&#x59CB;&#x672C;&#x7AE0;&#x8282;&#x524D;&#xFF0C;&#x601D;&#x8003;&#x4E00;&#x4E2A;&#x95EE;&#x9898;&#xFF1A;</p>
<p>&#x6211;&#x4EEC;&#x77E5;&#x9053;&#x5728; JavaScript &#x4E2D;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x6570;&#x7EC4;&#x4E2D;&#x4FDD;&#x5B58;&#x4E0D;&#x540C;&#x7C7B;&#x578B;&#x503C;&#xFF0C;&#x5E76;&#x4E14;&#x6570;&#x7EC4;&#x53EF;&#x4EE5;&#x52A8;&#x6001;&#x589E;&#x957F;&#xFF0C;&#x4E0D;&#x50CF;&#x5176;&#x5B83;&#x8BED;&#x8A00;&#xFF0C;&#x4F8B;&#x5982; C&#xFF0C;&#x521B;&#x5EFA;&#x7684;&#x65F6;&#x5019;&#x8981;&#x51B3;&#x5B9A;&#x6570;&#x7EC4;&#x7684;&#x5927;&#x5C0F;&#xFF0C;&#x5982;&#x679C;&#x6570;&#x7EC4;&#x6EE1;&#x4E86;&#xFF0C;&#x5C31;&#x8981;&#x91CD;&#x65B0;&#x7533;&#x8BF7;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#x3002;&#x8FD9;&#x662F;&#x4E3A;&#x4EC0;&#x4E48;&#x5583;&#xFF1F;</p>
<p>&#x672C;&#x8282;&#x4ECE; Chrome v8 &#x6E90;&#x7801;&#x89D2;&#x5EA6;&#x56DE;&#x7B54;&#x8FD9;&#x4E2A;&#x95EE;&#x9898;&#xFF0C;&#x5206;&#x4E3A;&#x56DB;&#x4E2A;&#x65B9;&#x9762;&#xFF1A;</p>
<ul>
<li>&#x6570;&#x7EC4;&#x57FA;&#x7840;&#x5165;&#x95E8;</li>
<li>JavaScript &#x4E2D;&#xFF0C;&#x6570;&#x7EC4;&#x4E3A;&#x4EC0;&#x4E48;&#x53EF;&#x4EE5;&#x4FDD;&#x5B58;&#x4E0D;&#x540C;&#x7C7B;&#x578B;&#xFF1F;</li>
<li>JavaScript &#x4E2D;&#xFF0C;&#x6570;&#x7EC4;&#x662F;&#x5982;&#x4F55;&#x5B58;&#x50A8;&#x7684;&#x5583;&#xFF1F;</li>
<li>JavaScript &#x4E2D;&#xFF0C;&#x6570;&#x7EC4;&#x7684;&#x52A8;&#x6001;&#x6269;&#x5BB9;&#x4E0E;&#x51CF;&#x5BB9;&#xFF08; <code>FastElements</code> &#xFF09;</li>
</ul>
<p>&#x4E0B;&#x9762;&#x8FDB;&#x5165;&#x6B63;&#x9898;&#x5427;&#xFF01;&#xFF08;&#x6587;&#x672B;&#x6709;&#x60CA;&#x559C;&#xFF09;&#x1F60A;</p>
<p>&#x60F3;&#x8981;&#x66F4;&#x591A;&#x66F4;&#x5FEB;&#x7684;&#x5B66;&#x4E60;&#x672C;&#x7CFB;&#x5217;&#xFF0C;&#x53EF;&#x4EE5;&#x5173;&#x6CE8;&#x516C;&#x4F17;&#x53F7;&#x300C;&#x524D;&#x7AEF;&#x74F6;&#x5B50;&#x541B;&#x300D;&#x548C;&#x6211;&#x7684;&#x300C;<a href="https://github.com/sisterAn/JavaScript-Algorithms" target="_blank">Github&#xFF08;&#x70B9;&#x51FB;&#x67E5;&#x770B;&#xFF09;</a>&#x300D;</p>
<h3 id="&#x4E00;&#x3001;&#x6570;&#x7EC4;&#xFF08;&#x57FA;&#x7840;&#xFF09;">&#x4E00;&#x3001;&#x6570;&#x7EC4;&#xFF08;&#x57FA;&#x7840;&#xFF09;</h3>
<p>&#x4E00;&#x79CD;&#x6700;&#x57FA;&#x7840;&#x7684;&#x6570;&#x636E;&#x7ED3;&#x6784;&#xFF0C;&#x6BCF;&#x79CD;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#x90FD;&#x6709;&#xFF0C;&#x5B83;&#x7F16;&#x53F7;&#x4ECE; 0 &#x5F00;&#x59CB;&#xFF0C;&#x4EE3;&#x8868;&#x4E00;&#x7EC4;&#x8FDE;&#x7EED;&#x7684;&#x50A8;&#x5B58;&#x7ED3;&#x6784;&#xFF0C;&#x7528;&#x6765;&#x50A8;&#x5B58;&#x540C;&#x4E00;&#x79CD;&#x7C7B;&#x578B;&#x7684;&#x6570;&#x636E;&#x3002;</p>
<pre class="language-"><code>let arr = [1, 2, 3]
</code></pre><p>&#x5B83;&#x7684;&#x8FD9;&#x79CD;&#x7279;&#x5B9A;&#x7684;&#x5B58;&#x50A8;&#x7ED3;&#x6784;&#xFF08;&#x8FDE;&#x7EED;&#x5B58;&#x50A8;&#x7A7A;&#x95F4;&#x5B58;&#x50A8;&#x540C;&#x4E00;&#x7C7B;&#x578B;&#x6570;&#x636E;&#xFF09;&#x51B3;&#x5B9A;&#x4E86;&#xFF1A;</p>
<p><strong>&#x4F18;&#x70B9;</strong></p>
<ul>
<li>&#x968F;&#x673A;&#x8BBF;&#x95EE;&#xFF1A;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4E0B;&#x6807;&#x968F;&#x673A;&#x8BBF;&#x95EE;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x4EFB;&#x610F;&#x4F4D;&#x7F6E;&#x4E0A;&#x7684;&#x6570;&#x636E;</li>
</ul>
<p><strong>&#x7F3A;&#x70B9;</strong></p>
<ul>
<li>&#x5BF9;&#x6570;&#x636E;&#x7684;&#x5220;&#x9664;&#x548C;&#x63D2;&#x5165;&#x4E0D;&#x662F;&#x5F88;&#x53CB;&#x597D;</li>
</ul>
<p><strong>&#x67E5;&#x627E;&#xFF1A;</strong> &#x6839;&#x636E;&#x4E0B;&#x6807;&#x968F;&#x673A;&#x8BBF;&#x95EE;&#x7684;&#x65F6;&#x95F4;&#x590D;&#x6742;&#x5EA6;&#x4E3A; O(1)&#xFF1B;</p>
<p><strong>&#x63D2;&#x5165;&#x6216;&#x5220;&#x9664;&#xFF1A;</strong> &#x65F6;&#x95F4;&#x590D;&#x6742;&#x5EA6;&#x4E3A; O(n)&#xFF1B;</p>
<p>&#x5728; JavaScript &#x4E2D;&#x7684;&#x6570;&#x7EC4;&#x51E0;&#x4E4E;&#x662F;&#x4E07;&#x80FD;&#x7684;&#xFF0C;&#x5B83;&#x4E0D;&#x5149;&#x53EF;&#x4EE5;&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x666E;&#x901A;&#x7684;&#x6570;&#x7EC4;&#x4F7F;&#x7528;&#xFF0C;&#x53EF;&#x4EE5;&#x4F5C;&#x4E3A;&#x6808;&#x6216;&#x961F;&#x5217;&#x4F7F;&#x7528;&#x3002;</p>
<p>&#x6570;&#x7EC4;&#xFF1A;</p>
<pre class="language-"><code>let array = [1, 2, 3]
</code></pre><p>&#x6808;&#xFF1A;</p>
<pre class="language-"><code>let stack = [1, 2, 3]
// &#x8FDB;&#x6808;
stack.push(4)
// &#x51FA;&#x6808;
stcak.pop()
</code></pre><p>&#x961F;&#x5217;&#xFF1A;</p>
<pre class="language-"><code>let queue = [1, 2, 3]
// &#x8FDB;&#x961F;
queue.push(4)
// &#x51FA;&#x961F;
queue.shift()
</code></pre><h3 id="&#x4E8C;&#x3001;javascript-&#x4E2D;&#xFF0C;&#x6570;&#x7EC4;&#x53EF;&#x4EE5;&#x4FDD;&#x5B58;&#x4E0D;&#x540C;&#x7C7B;&#x578B;&#x503C;">&#x4E8C;&#x3001;JavaScript &#x4E2D;&#xFF0C;&#x6570;&#x7EC4;&#x53EF;&#x4EE5;&#x4FDD;&#x5B58;&#x4E0D;&#x540C;&#x7C7B;&#x578B;&#x503C;</h3>
<p>&#x770B;&#x4E00;&#x4E0B; Chrome v8 &#x6E90;&#x7801;&#xFF1A;</p>
<pre class="language-"><code>// The JSArray describes JavaScript Arrays
//  Such an array can be in one of two modes:
//    - fast, backing storage is a FixedArray and length &lt;= elements.length();
//       Please note: push and pop can be used to grow and shrink the array.
//    - slow, backing storage is a HashTable with numbers as keys.
class JSArray: public JSObject {
 public:
  // [length]: The length property.
  DECL_ACCESSORS(length, Object)

  // ...

  // Number of element slots to pre-allocate for an empty array.
  static const int kPreallocatedArrayElements = 4;
};
</code></pre><p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x770B;&#x5230; <code>JSArray</code> &#x662F;&#x7EE7;&#x627F;&#x81EA; <code>JSObject</code> &#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x5728; JavaScript &#x4E2D;&#xFF0C;&#x6570;&#x7EC4;&#x53EF;&#x4EE5;&#x662F;&#x4E00;&#x4E2A;&#x7279;&#x6B8A;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x5185;&#x90E8;&#x4E5F;&#x662F;&#x4EE5; key-value &#x5F62;&#x5F0F;&#x5B58;&#x50A8;&#x6570;&#x636E;&#xFF0C;&#x6240;&#x4EE5; JavaScript &#x4E2D;&#x7684;&#x6570;&#x7EC4;&#x53EF;&#x4EE5;&#x5B58;&#x653E;&#x4E0D;&#x540C;&#x7C7B;&#x578B;&#x7684;&#x503C;&#x3002;</p>
<h3 id="&#x4E09;&#x3001;javascript-&#x4E2D;&#xFF0C;&#x6570;&#x7EC4;&#x7684;&#x5B58;&#x50A8;">&#x4E09;&#x3001;JavaScript &#x4E2D;&#xFF0C;&#x6570;&#x7EC4;&#x7684;&#x5B58;&#x50A8;</h3>
<pre class="language-"><code>// The JSArray describes JavaScript Arrays
//  Such an array can be in one of two modes:
//    - fast, backing storage is a FixedArray and length &lt;= elements.length();
//       Please note: push and pop can be used to grow and shrink the array.
//    - slow, backing storage is a HashTable with numbers as keys.
class JSArray: public JSObject {
 public:
  // [length]: The length property.
  DECL_ACCESSORS(length, Object)

  // ...

  // Number of element slots to pre-allocate for an empty array.
  static const int kPreallocatedArrayElements = 4;
};
</code></pre><p><code>JSArray</code> &#x7EE7;&#x627F;&#x4E8E; <code>JSObject</code> &#xFF0C;&#x4ECE;&#x6CE8;&#x91CA;&#x4E0A;&#x770B;&#xFF0C;&#x5B83;&#x6709;&#x4E24;&#x79CD;&#x5B58;&#x50A8;&#x65B9;&#x5F0F;&#xFF1A;</p>
<ul>
<li>fast&#xFF1A;&#x5B58;&#x50A8;&#x7ED3;&#x6784;&#x662F; <code>FixedArray</code> &#xFF0C;&#x5E76;&#x4E14;&#x6570;&#x7EC4;&#x957F;&#x5EA6; <code>&lt;= elements.length()</code> &#xFF0C;<code>push</code> &#x6216; <code>pop</code> &#x65F6;&#x53EF;&#x80FD;&#x4F1A;&#x4F34;&#x968F;&#x7740;&#x52A8;&#x6001;&#x6269;&#x5BB9;&#x6216;&#x51CF;&#x5BB9;</li>
<li>slow&#xFF1A;&#x5B58;&#x50A8;&#x7ED3;&#x6784;&#x662F; <code>HashTable</code>&#xFF08;&#x54C8;&#x5E0C;&#x8868;&#xFF09;&#xFF0C;&#x5E76;&#x4E14;&#x6570;&#x7EC4;&#x4E0B;&#x6807;&#x4F5C;&#x4E3A; <code>key</code></li>
</ul>
<p><code>fast</code> &#x6A21;&#x5F0F;&#x4E0B;&#x6570;&#x7EC4;&#x5728;&#x6E90;&#x7801;&#x91CC;&#x9762;&#x53EB; <code>FastElements</code> &#xFF0C;&#x800C; <code>slow</code> &#x6A21;&#x5F0F;&#x4E0B;&#x7684;&#x53EB;&#x505A; <code>SlowElements</code> &#x3002;</p>
<h4 id="1-&#x5FEB;&#x6570;&#x7EC4;&#xFF08;fastelements&#xFF09;">1. &#x5FEB;&#x6570;&#x7EC4;&#xFF08;FastElements&#xFF09;</h4>
<p><code>FixedArray</code> &#x662F; V8 &#x5B9E;&#x73B0;&#x7684;&#x4E00;&#x4E2A;&#x7C7B;&#x4F3C;&#x4E8E;&#x6570;&#x7EC4;&#x7684;&#x7C7B;&#xFF0C;&#x5B83;&#x8868;&#x793A;&#x4E00;&#x6BB5;&#x8FDE;&#x7EED;&#x7684;&#x5185;&#x5B58;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x7D22;&#x5F15;&#x76F4;&#x63A5;&#x5B9A;&#x4F4D;&#x3002;&#x65B0;&#x521B;&#x5EFA;&#x7684;&#x7A7A;&#x6570;&#x7EC4;&#x9ED8;&#x8BA4;&#x5C31;&#x662F;&#x5FEB;&#x6570;&#x7EC4;&#x3002;&#x5F53;&#x6570;&#x7EC4;&#x6EE1;&#xFF08;&#x6570;&#x7EC4;&#x7684;&#x957F;&#x5EA6;&#x8FBE;&#x5230;&#x6570;&#x7EC4;&#x5728;&#x5185;&#x5B58;&#x4E2D;&#x7533;&#x8BF7;&#x7684;&#x5185;&#x5B58;&#x5BB9;&#x91CF;&#x6700;&#x5927;&#x503C;&#xFF09;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x7EE7;&#x7EED; <code>push</code> &#x65F6;&#xFF0C; <code>JSArray</code> &#x4F1A;&#x8FDB;&#x884C;&#x52A8;&#x6001;&#x7684;&#x6269;&#x5BB9;&#xFF0C;&#x4EE5;&#x5B58;&#x50A8;&#x66F4;&#x591A;&#x7684;&#x5143;&#x7D20;&#x3002;</p>
<h4 id="2-&#x6162;&#x6570;&#x7EC4;&#xFF08;slowelements&#xFF09;">2. &#x6162;&#x6570;&#x7EC4;&#xFF08;SlowElements&#xFF09;</h4>
<p>&#x6162;&#x6570;&#x7EC4;&#x4EE5;&#x54C8;&#x5E0C;&#x8868;&#x7684;&#x5F62;&#x5F0F;&#x5B58;&#x50A8;&#x5728;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#x91CC;&#xFF0C;&#x5B83;&#x4E0D;&#x9700;&#x8981;&#x5F00;&#x8F9F;&#x8FDE;&#x7EED;&#x7684;&#x5B58;&#x50A8;&#x7A7A;&#x95F4;&#xFF0C;&#x4F46;&#x9700;&#x8981;&#x989D;&#x5916;&#x7EF4;&#x62A4;&#x4E00;&#x4E2A;&#x54C8;&#x5E0C;&#x8868;&#xFF0C;&#x4E0E;&#x5FEB;&#x6570;&#x7EC4;&#x76F8;&#x6BD4;&#xFF0C;&#x6027;&#x80FD;&#x76F8;&#x5BF9;&#x8F83;&#x5DEE;&#x3002;</p>
<pre class="language-"><code>// src/objects/dictionary.h
class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) Dictionary
    : public HashTable<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Derived,</span> <span class="token attr-name">Shape</span><span class="token punctuation">&gt;</span></span> {
  using DerivedHashTable = HashTable<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Derived,</span> <span class="token attr-name">Shape</span><span class="token punctuation">&gt;</span></span>;

 public:
  using Key = typename Shape::Key;
  // Returns the value at entry.
  inline Object ValueAt(InternalIndex entry);
  inline Object ValueAt(const Isolate* isolate, InternalIndex entry);

  // ...
};
</code></pre><p>&#x4ECE;&#x6E90;&#x7801;&#x4E2D;&#x53EF;&#x4EE5;&#x770B;&#x51FA;&#xFF0C;&#x5B83;&#x7684;&#x5185;&#x90E8;&#x5C31;&#x662F;&#x4E00;&#x4E2A; HashTable&#x3002;</p>
<h4 id="3-&#x4EC0;&#x4E48;&#x65F6;&#x5019;&#x4F1A;&#x4ECE;-fast-&#x8F6C;&#x53D8;&#x4E3A;-slow-&#x5583;&#xFF1F;">3. &#x4EC0;&#x4E48;&#x65F6;&#x5019;&#x4F1A;&#x4ECE; fast &#x8F6C;&#x53D8;&#x4E3A; slow &#x5583;&#xFF1F;</h4>
<p>&#x4ECE; Chrome V8 &#x6E90;&#x7801;&#x4E0A;&#x770B;&#xFF0C;</p>
<pre class="language-"><code>// src/objects/js-objects.h
static const uint32_t kMaxGap = 1024;

// src/objects/dictionary.h
// JSObjects prefer dictionary elements if the dictionary saves this much
// memory compared to a fast elements backing store.
static const uint32_t kPreferFastElementsSizeFactor = 3;

// src/objects/js-objects-inl.h
// If the fast-case backing storage takes up much more memory than a dictionary
// backing storage would, the object should have slow elements.
// static
static inline bool ShouldConvertToSlowElements(uint32_t used_elements,
                                               uint32_t new_capacity) {
  uint32_t size_threshold = NumberDictionary::kPreferFastElementsSizeFactor *
                            NumberDictionary::ComputeCapacity(used_elements) *
                            NumberDictionary::kEntrySize;
  // &#x5FEB;&#x6570;&#x7EC4;&#x65B0;&#x5BB9;&#x91CF;&#x662F;&#x6269;&#x5BB9;&#x540E;&#x7684;&#x5BB9;&#x91CF;3&#x500D;&#x4E4B;&#x591A;&#x65F6;&#xFF0C;&#x4E5F;&#x4F1A;&#x88AB;&#x8F6C;&#x6210;&#x6162;&#x6570;&#x7EC4;
  return size_threshold &lt;= new_capacity;
}

static inline bool ShouldConvertToSlowElements(JSObject object,
                                               uint32_t capacity,
                                               uint32_t index,
                                               uint32_t* new_capacity) {
  STATIC_ASSERT(JSObject::kMaxUncheckedOldFastElementsLength &lt;=
                JSObject::kMaxUncheckedFastElementsLength);
  if (index &lt; capacity) {
    *new_capacity = capacity;
    return false;
  }
  // &#x5F53;&#x52A0;&#x5165;&#x7684;&#x7D22;&#x5F15;&#x503C;&#xFF08;&#x4F8B;&#x5982;&#x4F8B;3&#x4E2D;&#x7684;2000&#xFF09;&#x6BD4;&#x5F53;&#x524D;&#x5BB9;&#x91CF;capacity &#x5927;&#x4E8E;&#x7B49;&#x4E8E; 1024&#x65F6;&#xFF0C;
  // &#x8FD4;&#x56DE;true&#xFF0C;&#x8F6C;&#x4E3A;&#x6162;&#x6570;&#x7EC4;
  if (index - capacity &gt;= JSObject::kMaxGap) return true;
  *new_capacity = JSObject::NewElementsCapacity(index + 1);
  DCHECK_LT(index, *new_capacity);
  // TODO(ulan): Check if it works with young large objects.
  if (*new_capacity &lt;= JSObject::kMaxUncheckedOldFastElementsLength ||
      (*new_capacity &lt;= JSObject::kMaxUncheckedFastElementsLength &amp;&amp;
       ObjectInYoungGeneration(object))) {
    return false;
  }
  return ShouldConvertToSlowElements(object.GetFastElementsUsage(),
                                     *new_capacity);
}
</code></pre><p>&#x6240;&#x4EE5;&#xFF0C;&#x5F53;&#x5904;&#x4E8E;&#x4EE5;&#x4E0B;&#x60C5;&#x51B5;&#x65F6;&#xFF0C;&#x5FEB;&#x6570;&#x7EC4;&#x4F1A;&#x88AB;&#x8F6C;&#x53D8;&#x4E3A;&#x6162;&#x6570;&#x7EC4;&#xFF1A;</p>
<ul>
<li>&#x5F53;&#x52A0;&#x5165;&#x7684;&#x7D22;&#x5F15;&#x503C; index &#x6BD4;&#x5F53;&#x524D;&#x5BB9;&#x91CF; capacity &#x5DEE;&#x503C;&#x5927;&#x4E8E;&#x7B49;&#x4E8E; 1024 &#x65F6;&#xFF08;index - capacity &gt;= 1024&#xFF09;</li>
<li>&#x5FEB;&#x6570;&#x7EC4;&#x65B0;&#x5BB9;&#x91CF;&#x662F;&#x6269;&#x5BB9;&#x540E;&#x7684;&#x5BB9;&#x91CF; 3 &#x500D;&#x4E4B;&#x591A;&#x65F6;</li>
</ul>
<p>&#x4F8B;&#x5982;&#xFF1A;&#x5411;&#x5FEB;&#x6570;&#x7EC4;&#x91CC;&#x589E;&#x52A0;&#x4E00;&#x4E2A;&#x5927;&#x7D22;&#x5F15;&#x540C;&#x7C7B;&#x578B;&#x503C;</p>
<pre class="language-"><code>var arr = [1, 2, 3]
arr[2000] = 10;
</code></pre><p>&#x5F53;&#x5F80; <code>arr</code> &#x589E;&#x52A0;&#x4E00;&#x4E2A; <code>2000</code> &#x7684;&#x7D22;&#x5F15;&#x65F6;&#xFF0C;<code>arr</code> &#x88AB;&#x8F6C;&#x6210;&#x6162;&#x6570;&#x7EC4;&#x3002;&#x8282;&#x7701;&#x4E86;&#x5927;&#x91CF;&#x7684;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#xFF08;&#x4ECE;&#x7D22;&#x5F15;&#x4E3A; 2 &#x5230;&#x7D22;&#x5F15;&#x4E3A; 2000&#xFF09;&#x3002;</p>
<h4 id="4-&#x4EC0;&#x4E48;&#x65F6;&#x5019;&#x4F1A;&#x4ECE;-slow-&#x8F6C;&#x53D8;&#x4E3A;-fast-&#x5583;&#xFF1F;">4. &#x4EC0;&#x4E48;&#x65F6;&#x5019;&#x4F1A;&#x4ECE; slow &#x8F6C;&#x53D8;&#x4E3A; fast &#x5583;&#xFF1F;</h4>
<p>&#x6211;&#x4EEC;&#x5DF2;&#x7ECF;&#x77E5;&#x9053;&#x5728;&#x4EC0;&#x4E48;&#x65F6;&#x5019;&#x4F1A;&#x51FA;&#x73B0;&#x7531;&#x5FEB;&#x53D8;&#x6162;&#xFF0C;&#x90A3;&#x7531;&#x6162;&#x53D8;&#x5FEB;&#x5C31;&#x5F88;&#x7B80;&#x5355;&#x4E86;</p>
<pre class="language-"><code>static bool ShouldConvertToFastElements(JSObject object,
                                        NumberDictionary dictionary,
                                        uint32_t index,
                                        uint32_t* new_capacity) {
  // If properties with non-standard attributes or accessors were added, we
  // cannot go back to fast elements.
  if (dictionary.requires_slow_elements()) return false;
  // Adding a property with this index will require slow elements.
  if (index &gt;= static_cast<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>uint32_t</span><span class="token punctuation">&gt;</span></span>(Smi::kMaxValue)) return false;
  if (object.IsJSArray()) {
    Object length = JSArray::cast(object).length();
    if (!length.IsSmi()) return false;
    *new_capacity = static_cast<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>uint32_t</span><span class="token punctuation">&gt;</span></span>(Smi::ToInt(length));
  } else if (object.IsJSArgumentsObject()) {
    return false;
  } else {
    *new_capacity = dictionary.max_number_key() + 1;
  }
  *new_capacity = Max(index + 1, *new_capacity);
  uint32_t dictionary_size = static_cast<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>uint32_t</span><span class="token punctuation">&gt;</span></span>(dictionary.Capacity()) *
                             NumberDictionary::kEntrySize;
  // Turn fast if the dictionary only saves 50% space.
  return 2 * dictionary_size &gt;= *new_capacity;
}
</code></pre><p>&#x5F53;&#x6162;&#x6570;&#x7EC4;&#x7684;&#x5143;&#x7D20;&#x53EF;&#x5B58;&#x653E;&#x5728;&#x5FEB;&#x6570;&#x7EC4;&#x4E2D;&#x4E14;&#x957F;&#x5EA6;&#x5728; smi &#x4E4B;&#x95F4;&#x4E14;&#x4EC5;&#x8282;&#x7701;&#x4E86;50%&#x7684;&#x7A7A;&#x95F4;&#xFF0C;&#x5219;&#x4F1A;&#x8F6C;&#x53D8;&#x4E3A;&#x5FEB;&#x6570;&#x7EC4;</p>
<h3 id="&#x56DB;&#x3001;javascript-&#x4E2D;&#xFF0C;&#x6570;&#x7EC4;&#x7684;&#x52A8;&#x6001;&#x6269;&#x5BB9;&#x4E0E;&#x51CF;&#x5BB9;&#xFF08;fastelements&#xFF09;">&#x56DB;&#x3001;JavaScript &#x4E2D;&#xFF0C;&#x6570;&#x7EC4;&#x7684;&#x52A8;&#x6001;&#x6269;&#x5BB9;&#x4E0E;&#x51CF;&#x5BB9;&#xFF08;FastElements&#xFF09;</h3>
<p>&#x9ED8;&#x8BA4;&#x7A7A;&#x6570;&#x7EC4;&#x521D;&#x59CB;&#x5316;&#x5927;&#x5C0F;&#x4E3A; <code>4</code> :</p>
<pre class="language-"><code>// Number of element slots to pre-allocate for an empty array.
static const int kPreallocatedArrayElements = 4;
</code></pre><p>&#x5728; JavaScript &#x4E2D;&#xFF0C;&#x5F53;&#x6570;&#x7EC4;&#x6267;&#x884C; <code>push</code> &#x64CD;&#x4F5C;&#x65F6;&#xFF0C;&#x4E00;&#x65E6;&#x53D1;&#x73B0;&#x6570;&#x7EC4;&#x5185;&#x5B58;&#x4E0D;&#x8DB3;&#xFF0C;&#x5C06;&#x8FDB;&#x884C;&#x6269;&#x5BB9;&#x3002;</p>
<p>&#x5728; Chrome &#x6E90;&#x7801;&#x4E2D;&#xFF0C; <code>push</code> &#x7684;&#x64CD;&#x4F5C;&#x662F;&#x7528;&#x6C47;&#x7F16;&#x5B9E;&#x73B0;&#x7684;&#xFF0C;&#x5728; c++ &#x91CC;&#x5D4C;&#x5165;&#x7684;&#x6C47;&#x7F16;&#xFF0C;&#x4EE5;&#x63D0;&#x9AD8;&#x6267;&#x884C;&#x6548;&#x7387;&#xFF0C;&#x5E76;&#x4E14;&#x5728;&#x6C47;&#x7F16;&#x7684;&#x57FA;&#x7840;&#x4E0A;&#x7528; c++ &#x5C01;&#x88C5;&#x4E86;&#x4E00;&#x5C42;&#xFF0C;&#x5728;&#x7F16;&#x8BD1;&#x6267;&#x884C;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F1A;&#x5C06;&#x8FD9;&#x4E9B; c++ &#x4EE3;&#x7801;&#x8F6C;&#x6210;&#x6C47;&#x7F16;&#x4EE3;&#x7801;&#x3002;</p>
<p>&#x8BA1;&#x7B97;&#x65B0;&#x5BB9;&#x91CF;&#x7684;&#x51FD;&#x6570;&#xFF1A;</p>
<pre class="language-"><code>// js-objects.h
static const uint32_t kMinAddedElementsCapacity = 16;

// code-stub-assembler.cc
Node* CodeStubAssembler::CalculateNewElementsCapacity(Node* old_capacity,
                                                      ParameterMode mode) {
  CSA_SLOW_ASSERT(this, MatchesParameterMode(old_capacity, mode));
  Node* half_old_capacity = WordOrSmiShr(old_capacity, 1, mode);
  Node* new_capacity = IntPtrOrSmiAdd(half_old_capacity, old_capacity, mode);
  Node* padding =
      IntPtrOrSmiConstant(JSObject::kMinAddedElementsCapacity, mode);
  return IntPtrOrSmiAdd(new_capacity, padding, mode);
}
</code></pre><p>&#x6240;&#x4EE5;&#x6269;&#x5BB9;&#x540E;&#x65B0;&#x5BB9;&#x91CF;&#x8BA1;&#x516C;&#x5F0F;&#x4E3A;&#xFF1A;</p>
<blockquote>
<p>new_capacity = old_capacity /2 + old_capacity + 16</p>
</blockquote>
<p>&#x5373;&#x8001;&#x7684;&#x5BB9;&#x91CF;&#x7684; 1.5 &#x500D;&#x52A0;&#x4E0A; 16 &#x3002;&#x521D;&#x59CB;&#x5316;&#x4E3A; 4 &#x4E2A;&#xFF0C;&#x5F53; <code>push</code> &#x7B2C; 5 &#x4E2A;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5BB9;&#x91CF;&#x5C06;&#x4F1A;&#x53D8;&#x6210;&#xFF1A;</p>
<blockquote>
<p>new_capacity = 4 / 2 + 4 + 16 = 22</p>
</blockquote>
<p>&#x63A5;&#x7740;&#x7533;&#x8BF7;&#x4E00;&#x5757;&#x8FD9;&#x4E48;&#x5927;&#x7684;&#x5185;&#x5B58;&#xFF0C;&#x628A;&#x8001;&#x7684;&#x6570;&#x636E;&#x62F7;&#x8FC7;&#x53BB;&#xFF0C;&#x628A;&#x65B0;&#x5143;&#x7D20;&#x653E;&#x5728;&#x5F53;&#x524D; length &#x4F4D;&#x7F6E;&#xFF0C;&#x7136;&#x540E;&#x5C06;&#x6570;&#x7EC4;&#x7684; length + 1&#xFF0C;&#x5E76;&#x8FD4;&#x56DE; length&#x3002;</p>
<p>&#x6240;&#x4EE5;&#xFF0C;&#x6269;&#x5BB9;&#x53EF;&#x4EE5;&#x5206;&#x4E3A;&#x4EE5;&#x4E0B;&#x51E0;&#x6B65;&#xFF1A;</p>
<ul>
<li><code>push</code> &#x64CD;&#x4F5C;&#x65F6;&#xFF0C;&#x53D1;&#x73B0;&#x6570;&#x7EC4;&#x5185;&#x5B58;&#x4E0D;&#x8DB3;</li>
<li>&#x7533;&#x8BF7; new_capacity = old_capacity /2 + old_capacity + 16 &#x90A3;&#x4E48;&#x957F;&#x5EA6;&#x7684;&#x5185;&#x5B58;&#x7A7A;&#x95F4;</li>
<li>&#x5C06;&#x6570;&#x7EC4;&#x62F7;&#x8D1D;&#x5230;&#x65B0;&#x5185;&#x5B58;&#x4E2D;</li>
<li>&#x628A;&#x65B0;&#x5143;&#x7D20;&#x653E;&#x5728;&#x5F53;&#x524D; length &#x4F4D;&#x7F6E;</li>
<li>&#x6570;&#x7EC4;&#x7684; length + 1</li>
<li>&#x8FD4;&#x56DE; length</li>
</ul>
<p>&#x6574;&#x4E2A;&#x8FC7;&#x7A0B;&#xFF0C;&#x7528;&#x6237;&#x662F;&#x65E0;&#x611F;&#x77E5;&#x7684;&#xFF0C;&#x4E0D;&#x50CF; C&#xFF0C;&#x9700;&#x7528;&#x7528;&#x6237;&#x624B;&#x52A8;&#x7533;&#x8BF7;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#x3002;</p>
<p>&#x5F53;&#x6570;&#x7EC4;&#x6267;&#x884C; <code>pop</code> &#x64CD;&#x4F5C;&#x65F6;&#xFF0C;&#x4F1A;&#x5224;&#x65AD; <code>pop</code> &#x540E;&#x6570;&#x7EC4;&#x7684;&#x5BB9;&#x91CF;&#xFF0C;&#x662F;&#x5426;&#x9700;&#x8981;&#x8FDB;&#x884C;&#x51CF;&#x5BB9;&#x3002;</p>
<p>&#x4E0D;&#x540C;&#x4E8E;&#x6570;&#x7EC4;&#x7684; <code>push</code> &#x4F7F;&#x7528;&#x6C47;&#x7F16;&#x5B9E;&#x73B0;&#x7684;&#xFF0C; <code>pop</code> &#x4F7F;&#x7528; c++ &#x5B9E;&#x73B0;&#x7684;&#x3002;</p>
<p>&#x5224;&#x65AD;&#x662F;&#x5426;&#x8FDB;&#x884C;&#x51CF;&#x5BB9;&#xFF1A;</p>
<pre class="language-"><code>if (2 * length &lt;= capacity) {
  // If more than half the elements won&apos;t be used, trim the array.
  isolate-&gt;heap()-&gt;RightTrimFixedArray(*backing_store, capacity - length);
} else {
  // Otherwise, fill the unused tail with holes.
  BackingStore::cast(*backing_store)-&gt;FillWithHoles(length, old_length);
}
</code></pre><p>&#x6240;&#x4EE5;&#xFF0C;&#x5F53;&#x6570;&#x7EC4; <code>pop</code> &#x540E;&#xFF0C;&#x5982;&#x679C;&#x6570;&#x7EC4;&#x5BB9;&#x91CF;&#x5927;&#x4E8E;&#x7B49;&#x4E8E; length &#x7684; 2 &#x500D;&#xFF0C;&#x5219;&#x8FDB;&#x884C;&#x5BB9;&#x91CF;&#x8C03;&#x6574;&#xFF0C;&#x4F7F;&#x7528; <code>RightTrimFixedArray</code> &#x51FD;&#x6570;&#xFF0C;&#x8BA1;&#x7B97;&#x51FA;&#x9700;&#x8981;&#x91CA;&#x653E;&#x7684;&#x7A7A;&#x95F4;&#x5927;&#x5C0F;&#xFF0C;&#x505A;&#x597D;&#x6807;&#x8BB0;&#xFF0C;&#x7B49;&#x5F85; GC &#x56DE;&#x6536;&#xFF1B;&#x5982;&#x679C;&#x6570;&#x7EC4;&#x5BB9;&#x91CF;&#x5C0F;&#x4E8E; length &#x7684; 2 &#x500D;&#xFF0C;&#x5219;&#x7528; holes &#x5BF9;&#x8C61;&#x586B;&#x5145;&#x3002;</p>
<p>&#x6240;&#x4EE5;&#xFF0C;&#x51CF;&#x5BB9;&#x53EF;&#x4EE5;&#x5206;&#x4E3A;&#x4EE5;&#x4E0B;&#x51E0;&#x6B65;&#xFF1A;</p>
<ul>
<li><code>pop</code> &#x64CD;&#x4F5C;&#x65F6;&#xFF0C;&#x83B7;&#x53D6;&#x6570;&#x7EC4; <code>length</code></li>
<li>&#x83B7;&#x53D6; <code>length - 1</code> &#x4E0A;&#x7684;&#x5143;&#x7D20;&#xFF08;&#x8981;&#x5220;&#x9664;&#x7684;&#x5143;&#x7D20;&#xFF09;</li>
<li>&#x6570;&#x7EC4; <code>length - 1</code></li>
<li>&#x5224;&#x65AD;&#x6570;&#x7EC4;&#x7684;&#x603B;&#x5BB9;&#x91CF;&#x662F;&#x5426;&#x5927;&#x4E8E;&#x7B49;&#x4E8E; length - 1 &#x7684; 2 &#x500D;</li>
<li>&#x662F;&#x7684;&#x8BDD;&#xFF0C;&#x4F7F;&#x7528; <code>RightTrimFixedArray</code> &#x51FD;&#x6570;&#xFF0C;&#x8BA1;&#x7B97;&#x51FA;&#x9700;&#x8981;&#x91CA;&#x653E;&#x7684;&#x7A7A;&#x95F4;&#x5927;&#x5C0F;&#xFF0C;&#x5E76;&#x505A;&#x597D;&#x6807;&#x8BB0;&#xFF0C;&#x7B49;&#x5F85; <code>GC</code> &#x56DE;&#x6536;</li>
<li>&#x4E0D;&#x662F;&#x7684;&#x8BDD;&#xFF0C;&#x7528; <code>holes</code> &#x5BF9;&#x8C61;&#x586B;&#x5145;</li>
<li>&#x8FD4;&#x56DE;&#x8981;&#x5220;&#x9664;&#x7684;&#x5143;&#x7D20;</li>
</ul>
<h3 id="&#x4E94;&#x3001;&#x89E3;&#x7B54;&#x5F00;&#x7BC7;&#x95EE;&#x9898;">&#x4E94;&#x3001;&#x89E3;&#x7B54;&#x5F00;&#x7BC7;&#x95EE;&#x9898;</h3>
<p>JavaScript &#x4E2D;&#xFF0C; <code>JSArray</code> &#x7EE7;&#x627F;&#x81EA; <code>JSObject</code> &#xFF0C;&#x6216;&#x8005;&#x8BF4;&#x5B83;&#x5C31;&#x662F;&#x4E00;&#x4E2A;&#x7279;&#x6B8A;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x5185;&#x90E8;&#x662F;&#x4EE5; key-value &#x5F62;&#x5F0F;&#x5B58;&#x50A8;&#x6570;&#x636E;&#xFF0C;&#x6240;&#x4EE5; JavaScript &#x4E2D;&#x7684;&#x6570;&#x7EC4;&#x53EF;&#x4EE5;&#x5B58;&#x653E;&#x4E0D;&#x540C;&#x7C7B;&#x578B;&#x7684;&#x503C;&#x3002;&#x5B83;&#x6709;&#x4E24;&#x79CD;&#x5B58;&#x50A8;&#x65B9;&#x5F0F;&#xFF0C;&#x5FEB;&#x6570;&#x7EC4;&#x4E0E;&#x6162;&#x6570;&#x7EC4;&#xFF0C;&#x521D;&#x59CB;&#x5316;&#x7A7A;&#x6570;&#x7EC4;&#x65F6;&#xFF0C;&#x4F7F;&#x7528;&#x5FEB;&#x6570;&#x7EC4;&#xFF0C;&#x5FEB;&#x6570;&#x7EC4;&#x4F7F;&#x7528;&#x8FDE;&#x7EED;&#x7684;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#xFF0C;&#x5F53;&#x6570;&#x7EC4;&#x957F;&#x5EA6;&#x8FBE;&#x5230;&#x6700;&#x5927;&#x65F6;&#xFF0C;<code>JSArray</code> &#x4F1A;&#x8FDB;&#x884C;&#x52A8;&#x6001;&#x7684;&#x6269;&#x5BB9;&#xFF0C;&#x4EE5;&#x5B58;&#x50A8;&#x66F4;&#x591A;&#x7684;&#x5143;&#x7D20;&#xFF0C;&#x76F8;&#x5BF9;&#x6162;&#x6570;&#x7EC4;&#xFF0C;&#x6027;&#x80FD;&#x8981;&#x597D;&#x5F97;&#x591A;&#x3002;&#x5F53;&#x6570;&#x7EC4;&#x4E2D; <code>hole</code> &#x592A;&#x591A;&#x65F6;&#xFF0C;&#x4F1A;&#x8F6C;&#x53D8;&#x6210;&#x6162;&#x6570;&#x7EC4;&#xFF0C;&#x5373;&#x4EE5;&#x54C8;&#x5E0C;&#x8868;&#x7684;&#x65B9;&#x5F0F;&#xFF08; key-value &#x7684;&#x5F62;&#x5F0F;&#xFF09;&#x5B58;&#x50A8;&#x6570;&#x636E;&#xFF0C;&#x4EE5;&#x8282;&#x7701;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#x3002;</p>
<h3 id="&#x516D;&#x3001;&#x6700;&#x540E;&#x9644;&#x8D60;&#x4E00;&#x9053;&#x524D;&#x7AEF;&#x9762;&#x8BD5;&#x9898;&#xFF08;&#x817E;&#x8BAF;&#xFF09;&#xFF1A;&#x6570;&#x7EC4;&#x6241;&#x5E73;&#x5316;&#x3001;&#x53BB;&#x91CD;&#x3001;&#x6392;&#x5E8F;">&#x516D;&#x3001;&#x6700;&#x540E;&#x9644;&#x8D60;&#x4E00;&#x9053;&#x524D;&#x7AEF;&#x9762;&#x8BD5;&#x9898;&#xFF08;&#x817E;&#x8BAF;&#xFF09;&#xFF1A;&#x6570;&#x7EC4;&#x6241;&#x5E73;&#x5316;&#x3001;&#x53BB;&#x91CD;&#x3001;&#x6392;&#x5E8F;</h3>
<p>&#x5173;&#x4E8E; <code>Array</code> &#x7684;&#x5C5E;&#x6027;&#x3001;&#x65B9;&#x6CD5;&#x8FD9;&#x91CC;&#x4E0D;&#x518D;&#x505A;&#x4ECB;&#x7ECD;&#xFF0C;&#x8BE6;&#x770B; <a href="https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array" target="_blank">MDN Array</a> &#x3002;</p>
<p>&#x9762;&#x8BD5;&#x9898;&#xFF1A;</p>
<blockquote>
<p>&#x5DF2;&#x77E5;&#x5982;&#x4E0B;&#x6570;&#x7EC4;&#xFF1A;var arr = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10];</p>
<p>&#x7F16;&#x5199;&#x4E00;&#x4E2A;&#x7A0B;&#x5E8F;&#x5C06;&#x6570;&#x7EC4;&#x6241;&#x5E73;&#x5316;&#x53BB;&#x5E76;&#x9664;&#x5176;&#x4E2D;&#x91CD;&#x590D;&#x90E8;&#x5206;&#x6570;&#x636E;&#xFF0C;&#x6700;&#x7EC8;&#x5F97;&#x5230;&#x4E00;&#x4E2A;&#x5347;&#x5E8F;&#x4E14;&#x4E0D;&#x91CD;&#x590D;&#x7684;&#x6570;&#x7EC4;</p>
</blockquote>
<p>&#x7B54;&#x6848;&#xFF1A;</p>
<pre class="language-"><code>var arr = [ [1, 2, 2], [3, 4, 5, 5], [6, 7, 8, 9, [11, 12, [12, 13, [14] ] ] ], 10]
// &#x6241;&#x5E73;&#x5316;
let flatArr = arr.flat(4)
// &#x53BB;&#x91CD;
let disArr = Array.from(new Set(flatArr))
// &#x6392;&#x5E8F;
let result = disArr.sort(function(a, b) {
    return a-b
})
console.log(result)
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
</code></pre><p>&#x5173;&#x4E8E; Set &#x8BF7;&#x67E5;&#x9605; <a href="https://github.com/LuNaHaiJiao/blog/issues/24" target="_blank">Set&#x3001;WeakSet&#x3001;Map&#x53CA;WeakMap</a></p>
<p>&#x53C2;&#x8003;&#x94FE;&#x63A5;&#xFF1A;</p>
<p><a href="https://juejin.im/post/5d80919b51882538036fc87d" target="_blank">&#x63A2;&#x7A76;JS V8&#x5F15;&#x64CE;&#x4E0B;&#x7684;&#x201C;&#x6570;&#x7EC4;&#x201D;&#x5E95;&#x5C42;&#x5B9E;&#x73B0;</a></p>
<p><a href="https://zhuanlan.zhihu.com/p/26388217" target="_blank">&#x4ECE;Chrome&#x6E90;&#x7801;&#x770B;JS Array&#x7684;&#x5B9E;&#x73B0;</a></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="统计算法的执行效率和资源消耗.html" class="navigation navigation-prev " aria-label="Previous page: 统计算法的执行效率和资源消耗">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="LRU算法.html" class="navigation navigation-next " aria-label="Next page: LRU算法">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"从Chrome V8源码看JavaScript数组","level":"1.5.3","depth":2,"next":{"title":"LRU算法","level":"1.5.4","depth":2,"path":"Algorithm/LRU算法.md","ref":"Algorithm/LRU算法.md","articles":[]},"previous":{"title":"统计算法的执行效率和资源消耗","level":"1.5.2","depth":2,"path":"Algorithm/统计算法的执行效率和资源消耗.md","ref":"Algorithm/统计算法的执行效率和资源消耗.md","articles":[]},"dir":"ltr"},"config":{"plugins":["github","donate","splitter","-anchor-navigation-ex","-sharing","sharing-plus","-highlight","prism","toggle-chapters","-lunr","-search","search-plus"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"prism":{"css":["prismjs/themes/prism.css"]},"github":{"url":"https://github.com/MarioGogogo"},"splitter":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"donate":{"alipay":"","alipayText":"支付宝打赏","button":"赏","title":"","wechat":"http://7q5c2h.com1.z0.glb.clouddn.com/wechatpay.JPG","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"serif","size":2},"anchor-navigation-ex":{"associatedWithSummary":false,"showLevel":true,"multipleH1":true,"mode":"float","pageTop":{"showLevelIcon":false,"level1Icon":"fa fa-hand-o-right","level2Icon":"fa fa-hand-o-right","level3Icon":"fa fa-hand-o-right"}},"sharing":{"qq":false,"all":["weibo","qq","qzone","google","douban"],"douban":false,"facebook":false,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":true},"toggle-chapters":{},"search-plus":{}},"theme":"default","author":"WuXiaolong","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"👨🏽‍💻前端漫游指南","language":"zh-hans","links":{"sidebar":{}},"gitbook":"3.2.3","description":"http://h5web.cc/"},"file":{"path":"Algorithm/从Chrome V8源码看JavaScript数组.md","mtime":"2020-04-17T09:06:51.839Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-04-22T01:16:46.955Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

